load("@rules_proto//proto:defs.bzl", "proto_library")
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")

proto_library(
    name = "rpc_proto",
    srcs = ["rpc.proto"],
    visibility = ["//visibility:public"],
    deps = ["@com_google_protobuf//:timestamp_proto"],
)

go_proto_library(
    name = "rpc_go_proto",
    compilers = ["@io_bazel_rules_go//proto:go_grpc"],
    importpath = "go.f110.dev/heimdallr/pkg/server/rpc",
    proto = ":rpc_proto",
    visibility = ["//visibility:private"],
)

go_library(
    name = "rpc",
    srcs = [
        "const.go",
        "interface.go",
        "method_matcher.go",
        "rpc.pb.go",
        "util.go",
    ],
    importpath = "go.f110.dev/heimdallr/pkg/rpc",
    visibility = ["//visibility:public"],
    deps = [
        "//pkg/database",
        "//vendor/github.com/golang/protobuf/proto",
        "//vendor/github.com/golang/protobuf/ptypes",
        "//vendor/github.com/golang/protobuf/ptypes/timestamp",
        "//vendor/golang.org/x/xerrors",
        "//vendor/google.golang.org/grpc",
        "//vendor/google.golang.org/grpc/codes",
        "//vendor/google.golang.org/grpc/status",
        "//vendor/google.golang.org/protobuf/reflect/protoreflect",
        "//vendor/google.golang.org/protobuf/runtime/protoimpl",
    ],
)

load("//build/rules/go:grpc.bzl", "vendor_grpc_source")

vendor_grpc_source(
    name = "vendor_grpc_source",
    src = ":rpc_go_proto",
    visibility = ["//visibility:public"],
)

go_test(
    name = "rpc_test",
    srcs = ["method_matcher_test.go"],
    embed = [":rpc"],
    deps = [
        "//vendor/github.com/stretchr/testify/assert",
        "//vendor/github.com/stretchr/testify/require",
    ],
)
